package com.shakespace.artofandroid.chapter01

import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.shakespace.artofandroid.R
import com.shakespace.artofandroid.chapter01.launchmode.AActivity
import com.shakespace.artofandroid.chapter01.lifecycle.LifecycleActivity
import com.shakespace.firstlinecode.global.TAG
import com.shakespace.firstlinecode.global.start
import kotlinx.android.synthetic.main.activity_chapter01.*

class Chapter01Activity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_chapter01)
        Log.e(this.TAG, "onCreate: ")

        initListener()
    }

    private fun initListener() {

        tv_one.setOnClickListener {
            start(LifecycleActivity::class.java)
        }

        tv_two.setOnClickListener {
            start(AActivity::class.java)

//            startActivity(Intent(this, CActivity::class.java).also {
//                it.flags = Intent.FLAG_ACTIVITY_NEW_TASK
//            })
        }
    }

    /**
     *
    TaskRecord{8c14cee #43614 A=com.shakespace.art U=0 StackId=1 sz=4}
    Run #16: ActivityRecord{c4671b0 u0 com.shakespace.artofandroid/.chapter01.launchmode.BActivity t43614}
    Run #15: ActivityRecord{fd52eb9 u0 com.shakespace.artofandroid/.chapter01.launchmode.AActivity t43614}
    Run #14: ActivityRecord{c0b6c61 u0 com.shakespace.artofandroid/.chapter01.launchmode.DActivity t43614}
    Run #13: ActivityRecord{e4d2e13 u0 com.shakespace.artofandroid/.chapter01.launchmode.CActivity t43614}
    TaskRecord{dd2758f #43613 A=com.shakespace.artofandroid U=0 StackId=1 sz=4}
    Run #12: ActivityRecord{3ed6352 u0 com.shakespace.artofandroid/.chapter01.launchmode.BActivity t43613}
    Run #11: ActivityRecord{b4ba1ee u0 com.shakespace.artofandroid/.chapter01.launchmode.AActivity t43613}
    Run #10: ActivityRecord{9b9d124 u0 com.shakespace.artofandroid/.chapter01.Chapter01Activity t43613}
    Run #9: ActivityRecord{1206efb u0 com.shakespace.artofandroid/.MainActivity t43613}
     */

    // 2020-01-06 NOTE:  run adb shell dumpsys activity  in terminal
    // search Running activities  to check TaskStack

    override fun onStart() {
        super.onStart()
        Log.e(TAG, "onStart: ")
    }

    override fun onResume() {
        super.onResume()
        Log.e(this.TAG, "onResume: ")
    }

    override fun onPause() {
        super.onPause()
        // 2020-01-06 NOTE:  donot do too much work here
        Log.e(this.TAG, "onPause: ")
    }

    override fun onStop() {
        super.onStop()
        Log.e(this.TAG, "onStop: ")
    }

    override fun onDestroy() {
        super.onDestroy()
        Log.e(this.TAG, "onDestroy: ")
    }
}
